*	************************************************************************
* 	File-Name: 		.do
*	Date:  			04/26/2016
*	Authors: 		Eugenie Dugoua
*	Data Used:  		Data_Merged_7_05.dta
*	Purpose:   		Analysis
*	Software:		Stata SE 12.1
*	Machine:		Stata for Windows through Linux Wine
*	************************************************************************

*	************************************************************************
*	DIRECTORY                                                               
*	************************************************************************
cap cd "/home/emd/Dropbox/Night Lights Validation (Eugenie, Ryan, Johannes)"
clear all
use "./Data/Python_code_merging/Data_Merged_11_20_stata.dta"

*JU FILE PATH, WD
*use "/home/jurpelai/Dropbox/Night Lights Validation (Eugenie, Ryan, Johannes)/Data/Python_code_merging/Data_Merged_8_13_stata.dta"
*cd "/home/jurpelai/Dropbox/Night Lights Validation (Eugenie, Ryan, Johannes)"

*RK File Path, WD
*cd "C:/Users/Ryan/Dropbox/Night Lights Validation (Eugenie, Ryan, Johannes)"
*clear
*use "./Data/Python_code_merging/Data_Merged_8_13_stata.dta"


**************************************
* REGRESSION 1: MAIN             
**************************************
eststo clear

eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace
* Create boxplot of residuals
predict m1res, residuals
graph box m1res, over(SH_sum_11_cat) ytitle(Residuals from Table 1 Model 1) ylabel(-10(2)6) title(Regression Using Shapefile log(sum DN)) scheme(s1mono) name(hhshres)

xtset St11 
eststo: quietly xtreg electrified_hh_nbr_log SH_sum_11_log, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg electrified_hh_nbr_log SH_sum_11_log, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg electrified_hh_nbr_log SH_sum_11_log, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logdummy, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logdummy, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logdummy, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logdummy, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

esttab using "./Manuscript/Tables/results.tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(  %~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Number of households with electricity (log).")

**************************************
* REGRESSION 2: NON-ELEC               
**************************************

eststo clear

eststo: quietly reg nonelectrified_hh_nbr_log SH_sum_11_log, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg nonelectrified_hh_nbr_log SH_sum_11_log, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg nonelectrified_hh_nbr_log SH_sum_11_log, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg nonelectrified_hh_nbr_log SH_sum_11_log, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

eststo: quietly reg nonelectrified_hh_nbr_log SH_sum_11_log SH_sum_11_logdummy, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg nonelectrified_hh_nbr_log SH_sum_11_log SH_sum_11_logdummy, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg nonelectrified_hh_nbr_log SH_sum_11_log SH_sum_11_logdummy, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg nonelectrified_hh_nbr_log SH_sum_11_log SH_sum_11_logdummy, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace


esttab using "./Manuscript/Tables/non_results.tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(  %~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Number of households without electricity (log).")




**************************************
* REGRESSION 3: NON-LINEAR REGRESSION  - POLYNOMIAL
**************************************

eststo clear

eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_log2, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_log2 SH_sum_11_log3, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_log2 SH_sum_11_log3 SH_sum_11_log4, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

esttab using "./Manuscript/Tables//nonlinear_polynomial.tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(%~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state"  "Fixed effects: district" "Fixed effects: subdistrict" ///
  "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Number of households with electricity (log).")

**************************************
* REGRESSION 4: NON-LINEAR REGRESSION - DUMMIES
**************************************

scalar drop _all
centile SH_sum_11_log_nonzero, centile(10(10)90)
return list
forvalues i = 1/9 {
scalar p`i' = r(c_`i')
}
scalar list 
         
gen light_dummy = .
replace light_dummy = 0 if SH_sum_11_log == 0
replace light_dummy = 1 if SH_sum_11_log > 0 & SH_sum_11_log < p2
replace light_dummy = 2 if SH_sum_11_log >= p2 & SH_sum_11_log < p4
replace light_dummy = 3 if SH_sum_11_log >= p4 & SH_sum_11_log < p6
replace light_dummy = 4 if SH_sum_11_log >= p6 & SH_sum_11_log < p8
replace light_dummy = 5 if SH_sum_11_log >= p8 & SH_sum_11_log != .

gen light_dummy0 = .
replace light_dummy0 = 1 if light_dummy == 0
replace light_dummy0 = 0 if light_dummy == 1 | light_dummy == 2 | light_dummy == 3 | light_dummy == 4 | light_dummy == 5 
label variable light_dummy0 "Night lights zero"

gen light_dummy1 = .
replace light_dummy1 = 1 if light_dummy == 1
replace light_dummy1 = 0 if light_dummy == 0 | light_dummy == 2 | light_dummy == 3 | light_dummy == 4 | light_dummy == 5 
label variable light_dummy1 "Night lights 0-20th percentile"

gen light_dummy2 = .
replace light_dummy2 = 1 if light_dummy == 2
replace light_dummy2 = 0 if light_dummy == 1 | light_dummy == 0 | light_dummy == 3 | light_dummy == 4 | light_dummy == 5 
label variable light_dummy2 "Night lights 20th-40th percentile"

gen light_dummy3 = .
replace light_dummy3 = 1 if light_dummy == 3
replace light_dummy3 = 0 if light_dummy == 1 | light_dummy == 2 | light_dummy == 0 | light_dummy == 4 | light_dummy == 5 
label variable light_dummy3 "Night lights 40th-60th percentile"

gen light_dummy4 = .
replace light_dummy4 = 1 if light_dummy == 4
replace light_dummy4 = 0 if light_dummy == 1 | light_dummy == 2 | light_dummy == 3 | light_dummy == 0 | light_dummy == 5 
label variable light_dummy4 "Night lights 60th-80th percentile"

gen light_dummy5 = .
replace light_dummy5 = 1 if light_dummy == 5
replace light_dummy5 = 0 if light_dummy == 1 | light_dummy == 2 | light_dummy == 3 | light_dummy == 4 | light_dummy == 0 
label variable light_dummy5 "Night lights 80th-100th percentile"

eststo clear

eststo: quietly reg electrified_hh_nbr_log light_dummy1 light_dummy2 light_dummy3 light_dummy4 light_dummy5, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11
eststo: quietly xtreg electrified_hh_nbr_log light_dummy1 light_dummy2 light_dummy3 light_dummy4 light_dummy5, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg electrified_hh_nbr_log light_dummy1 light_dummy2 light_dummy3 light_dummy4 light_dummy5, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg electrified_hh_nbr_log light_dummy1 light_dummy2 light_dummy3 light_dummy4 light_dummy5, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

esttab using "./Manuscript/Tables/nonlinear_dummy.tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(%~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Number of households with electricity (log)." ///
"Night lights: Omitted category is when night light values are null." )

**************************************
* REGRESSION 5: REGRESSION WITH API MEAN DATA (ONLY WHERE SHAPE DATA NOT MISSING)                   
**************************************
* St11 Dis11_fe Subd11_fe

eststo clear


eststo: quietly reg electrified_hh_nbr_log API_mean_2011_log if SH_sum_11_log < .
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace
* Create boxplot of residuals
predict m2res, residuals
graph box m2res, over(API_mean_2011_cat) ytitle(Residuals from Table 5 Model 1) ylabel(-10(2)6) title(Regression Using India Lights log(mean DN)) scheme(s1mono) name(hhiores)


xtset St11 
eststo: quietly xtreg electrified_hh_nbr_log API_mean_2011_log if SH_sum_11_log < ., fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg electrified_hh_nbr_log API_mean_2011_log if SH_sum_11_log < ., fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg electrified_hh_nbr_log API_mean_2011_log if SH_sum_11_log < ., fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

eststo: quietly reg electrified_hh_nbr_log API_mean_2011_log API_mean_2011_logdummy if SH_sum_11_log < ., vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg electrified_hh_nbr_log API_mean_2011_log API_mean_2011_logdummy if SH_sum_11_log < ., fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg electrified_hh_nbr_log API_mean_2011_log API_mean_2011_logdummy if SH_sum_11_log < ., fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg electrified_hh_nbr_log API_mean_2011_log API_mean_2011_logdummy if SH_sum_11_log < ., fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

esttab using "./Manuscript/Tables/results(apimean).tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(%~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Number of households with electricity (log).")


**************************************
* REGRESSION 6: REGRESSION WITH API MAXIMUM DATA (ONLY WHERE SHAPE DATA NOT MISSING)                   
**************************************

eststo clear

eststo: quietly reg electrified_hh_nbr_log API_max_2011_log if SH_sum_11_log < .
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace
* Create boxplot of residuals
predict m3res, residuals
graph box m3res, over(API_max_2011_cat) ytitle(Residuals from Table 6 Model 1) ylabel(-10(2)6) title(Regression Using India Lights log(max DN)) scheme(s1mono) name(hhiomres)

xtset St11 
eststo: quietly xtreg electrified_hh_nbr_log API_max_2011_log if SH_sum_11_log < ., fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg electrified_hh_nbr_log API_max_2011_log if SH_sum_11_log < ., fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg electrified_hh_nbr_log API_max_2011_log if SH_sum_11_log < ., fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

esttab using "./Manuscript/Tables/results(apimax).tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(%~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Number of households with electricity (log).")


* Combine residual boxplots
graph combine hhshres hhiores hhiomres, scheme(s1mono) xsize(7) ysize(4)


**************************************
* REGRESSION 7: WITH NIGHT LIGHTS AS DV
**************************************
eststo clear

eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log 
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace
 
eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log  c11_2011_total_area c01_2001_dist_town
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace
 
eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log  c11_2011_power_all c11_2011_asset_availing_bank 
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace
 
eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log  c11_2011_total_area c01_2001_dist_town ///
c11_2011_total_hhs c11_2011_total_pop c11_2011_total_sc_pop c11_2011_total_st_pop ///
c11_2011_p_lit c11_2011_power_all c11_2011_asset_availing_bank
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe

eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log  c11_2011_total_area c01_2001_dist_town ///
c11_2011_total_hhs c11_2011_total_pop c11_2011_total_sc_pop c11_2011_total_st_pop ///
c11_2011_p_lit c11_2011_power_all c11_2011_asset_availing_bank, fe vce(cluster Subd11_fe)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

label variable SH_sum_11_log "logNL sh sum "
esttab using "/home/emd/Dropbox/Night Lights Validation (Eugenie, Ryan, Johannes)/Analysis/predicting_NL.tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(%~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01)  nomtitles ///
addnote ("Dependent variable: Night lights (shape, log of sum, 2011).")


*******************************************
* not in the paper
*******************************************

**************************************
*  REGRESSION : LINEAR REGRESSION OF NIGHT LIGHTS, WITH CONTROLS
**************************************

eststo clear

eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_power_all c11_2011_asset_availing_bank c11_2011_asset_none c11_2011_asset_tv c11_2011_asset_radio_transitor log_dist, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_power_all c11_2011_asset_availing_bank c11_2011_asset_none c11_2011_asset_tv c11_2011_asset_radio_transitor log_dist, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_power_all c11_2011_asset_availing_bank c11_2011_asset_none c11_2011_asset_tv c11_2011_asset_radio_transitor log_dist, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_power_all c11_2011_asset_availing_bank c11_2011_asset_none c11_2011_asset_tv c11_2011_asset_radio_transitor log_dist, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

esttab using "./Manuscript/Tables/results_lights.tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(  %~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Night lights (shape, log of sum, 2011).")







**************************************
*  REGRESSION WITH NO ASSETS: LINEAR REGRESSION OF NIGHT LIGHTS 
**************************************

eststo clear

eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_none, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_none log_dist, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none log_dist, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none log_dist, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

xtset Subd11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none log_dist, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

esttab using "./Manuscript/Tables/results_lights_noassets.tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(  %~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Night lights (shape, log of sum, 2011).")






**************************************
*  REGRESSION WITH TV: LINEAR REGRESSION OF NIGHT LIGHTS 
**************************************

eststo clear

eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_tv, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_tv log_dist, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv log_dist, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv log_dist, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

xtset Subd11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv log_dist, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

esttab using "./Manuscript/Tables/results_lights_TV.tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(  %~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Night lights (shape, log of sum, 2011).")





**************************************
*  REGRESSION WITH bank account LINEAR REGRESSION OF NIGHT LIGHTS 
**************************************

eststo clear

eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_availing_bank, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

eststo: quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_availing_bank log_dist, vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset St11 
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank log_dist, fe vce(cluster St11)
estadd local state "Yes" , replace
estadd local district "No" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Dis11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank log_dist, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "Yes" , replace
estadd local subdistrict "No" , replace

xtset Subd11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

xtset Subd11_fe
eststo: quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank log_dist, fe vce(cluster St11)
estadd local state "No" , replace
estadd local district "No" , replace
estadd local subdistrict "Yes" , replace

esttab using "./Manuscript/Tables/results_lights_assetbank.tex", ///
replace b(%9.3f)  ///
stats(state district subdistrict r2 N, ///
fmt(  %~12s %~12s %~12s %9.3f %9.3g) ///
label("Fixed effects: state" "Fixed effects: district" "Fixed effects: subdistrict" ///
 "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Night lights (shape, log of sum, 2011).")


**************************************
*  Plot with additional economic variables
**************************************

* Table S9
quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_none, vce(cluster St11)
estimates store mod1

quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_none log_dist, vce(cluster St11)
estimates store mod2

xtset St11 
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none, fe vce(cluster St11)
estimates store mod3

xtset St11 
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none log_dist, fe vce(cluster St11)
estimates store mod4

xtset Dis11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none, fe vce(cluster St11)
estimates store mod5

xtset Dis11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none log_dist, fe vce(cluster St11)
estimates store mod6

xtset Subd11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none, fe vce(cluster St11)
estimates store mod7

xtset Subd11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_none log_dist, fe vce(cluster St11)
estimates store mod8

coefplot (mod1, label(no FE)) (mod2, label(no FE, Distance to Town)) (mod3, label(State FE)) (mod4, label(State FE, Distance to Town)) ///
(mod5, label(District FE)) (mod6, label(District FE, Distance to Town)) (mod7, label(Subdistrict FE)) ///
(mod8, label(Subdistrict FE, Distance to Town)), drop(_cons electrified_hh_nbr_log nonelectrified_hh_nbr_log log_dist) ///
yscale(off) xlabel(-0.03(0.01)0.03) xline(0) title(Households Without Assets) legend(cols(1)) scheme(s1color) name(g1)


* Table S10
quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_tv, vce(cluster St11)
estimates store mod1

quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_tv log_dist, vce(cluster St11)
estimates store mod2

xtset St11 
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv, fe vce(cluster St11)
estimates store mod3

xtset St11 
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv log_dist, fe vce(cluster St11)
estimates store mod4

xtset Dis11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv, fe vce(cluster St11)
estimates store mod5

xtset Dis11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv log_dist, fe vce(cluster St11)
estimates store mod6

xtset Subd11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv, fe vce(cluster St11)
estimates store mod7

xtset Subd11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_tv log_dist, fe vce(cluster St11)
estimates store mod8

coefplot (mod1, label(no FE)) (mod2, label(no FE, Distance to Town)) (mod3, label(State FE)) (mod4, label(State FE, Distance to Town)) ///
(mod5, label(District FE)) (mod6, label(District FE, Distance to Town)) (mod7, label(Subdistrict FE)) ///
(mod8, label(Subdistrict FE, Distance to Town)), drop(_cons electrified_hh_nbr_log nonelectrified_hh_nbr_log log_dist) ///
yscale(off) xlabel(-0.03(0.01)0.03) xline(0) title(Households With TV) legend(cols(1)) scheme(s1color) name(g2)

* Table S11
quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_availing_bank, vce(cluster St11)
estimates store mod1

quietly reg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log  c11_2011_asset_availing_bank log_dist, vce(cluster St11)
estimates store mod2

xtset St11 
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank, fe vce(cluster St11)
estimates store mod3

xtset St11 
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank log_dist, fe vce(cluster St11)
estimates store mod4

xtset Dis11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank, fe vce(cluster St11)
estimates store mod5

xtset Dis11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank log_dist, fe vce(cluster St11)
estimates store mod6

xtset Subd11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank, fe vce(cluster St11)
estimates store mod7

xtset Subd11_fe
quietly xtreg SH_sum_11_log electrified_hh_nbr_log nonelectrified_hh_nbr_log c11_2011_asset_availing_bank log_dist, fe vce(cluster St11)
estimates store mod8

coefplot (mod1, label(no FE)) (mod2, label(no FE, Distance to Town)) (mod3, label(State FE)) (mod4, label(State FE, Distance to Town)) ///
(mod5, label(District FE)) (mod6, label(District FE, Distance to Town)) (mod7, label(Subdistrict FE)) ///
(mod8, label(Subdistrict FE, Distance to Town)), drop(_cons electrified_hh_nbr_log nonelectrified_hh_nbr_log log_dist) ///
yscale(off) xlabel(-0.03(0.01)0.03) xline(0) title(Households With Banking) legend(cols(1)) scheme(s1color) name(g3)

grc1leg g1 g2 g3, pos(4) ring(0) scheme(s1color)

**************************************
*  Plot with additional economic variables and no controls for electrification
**************************************

* Table S12
quietly reg SH_sum_11_log c11_2011_asset_none, vce(cluster St11)
estimates store mod1

quietly reg SH_sum_11_log c11_2011_asset_none log_dist, vce(cluster St11)
estimates store mod2

xtset St11 
quietly xtreg SH_sum_11_log c11_2011_asset_none, fe vce(cluster St11)
estimates store mod3

xtset St11 
quietly xtreg SH_sum_11_log c11_2011_asset_none log_dist, fe vce(cluster St11)
estimates store mod4

xtset Dis11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_none, fe vce(cluster St11)
estimates store mod5

xtset Dis11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_none log_dist, fe vce(cluster St11)
estimates store mod6

xtset Subd11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_none, fe vce(cluster St11)
estimates store mod7

xtset Subd11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_none log_dist, fe vce(cluster St11)
estimates store mod8

coefplot (mod1, label(no FE)) (mod2, label(no FE, Distance to Town)) (mod3, label(State FE)) (mod4, label(State FE, Distance to Town)) ///
(mod5, label(District FE)) (mod6, label(District FE, Distance to Town)) (mod7, label(Subdistrict FE)) ///
(mod8, label(Subdistrict FE, Distance to Town)), drop(_cons electrified_hh_nbr_log nonelectrified_hh_nbr_log log_dist) ///
yscale(off) xlabel(-0.03(0.01)0.03) xline(0) title(Households Without Assets) legend(cols(1)) scheme(s1color) name(g1)


* Table S13
quietly reg SH_sum_11_log c11_2011_asset_tv, vce(cluster St11)
estimates store mod1

quietly reg SH_sum_11_log c11_2011_asset_tv log_dist, vce(cluster St11)
estimates store mod2

xtset St11 
quietly xtreg SH_sum_11_log c11_2011_asset_tv, fe vce(cluster St11)
estimates store mod3

xtset St11 
quietly xtreg SH_sum_11_log c11_2011_asset_tv log_dist, fe vce(cluster St11)
estimates store mod4

xtset Dis11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_tv, fe vce(cluster St11)
estimates store mod5

xtset Dis11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_tv log_dist, fe vce(cluster St11)
estimates store mod6

xtset Subd11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_tv, fe vce(cluster St11)
estimates store mod7

xtset Subd11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_tv log_dist, fe vce(cluster St11)
estimates store mod8

coefplot (mod1, label(no FE)) (mod2, label(no FE, Distance to Town)) (mod3, label(State FE)) (mod4, label(State FE, Distance to Town)) ///
(mod5, label(District FE)) (mod6, label(District FE, Distance to Town)) (mod7, label(Subdistrict FE)) ///
(mod8, label(Subdistrict FE, Distance to Town)), drop(_cons electrified_hh_nbr_log nonelectrified_hh_nbr_log log_dist) ///
yscale(off) xlabel(-0.03(0.01)0.03) xline(0) title(Households With TV) legend(cols(1)) scheme(s1color) name(g2)

* Table S14
quietly reg SH_sum_11_log c11_2011_asset_availing_bank, vce(cluster St11)
estimates store mod1

quietly reg SH_sum_11_log c11_2011_asset_availing_bank log_dist, vce(cluster St11)
estimates store mod2

xtset St11 
quietly xtreg SH_sum_11_log c11_2011_asset_availing_bank, fe vce(cluster St11)
estimates store mod3

xtset St11 
quietly xtreg SH_sum_11_log c11_2011_asset_availing_bank log_dist, fe vce(cluster St11)
estimates store mod4

xtset Dis11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_availing_bank, fe vce(cluster St11)
estimates store mod5

xtset Dis11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_availing_bank log_dist, fe vce(cluster St11)
estimates store mod6

xtset Subd11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_availing_bank, fe vce(cluster St11)
estimates store mod7

xtset Subd11_fe
quietly xtreg SH_sum_11_log c11_2011_asset_availing_bank log_dist, fe vce(cluster St11)
estimates store mod8

coefplot (mod1, label(no FE)) (mod2, label(no FE, Distance to Town)) (mod3, label(State FE)) (mod4, label(State FE, Distance to Town)) ///
(mod5, label(District FE)) (mod6, label(District FE, Distance to Town)) (mod7, label(Subdistrict FE)) ///
(mod8, label(Subdistrict FE, Distance to Town)), drop(_cons electrified_hh_nbr_log nonelectrified_hh_nbr_log log_dist) ///
yscale(off) xlabel(-0.03(0.01)0.03) xline(0) title(Households With Banking) legend(cols(1)) scheme(s1color) name(g3)

grc1leg2 g1 g2 g3, pos(4) ring(0) scheme(s1color)


